package cn.edu.swu.user;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/AddUser")
public class addUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String newUserName=request.getParameter("newUserName");
        String newUserPsw=request.getParameter("newUserPsw");

        USER newUser=new USER(newUserName,newUserPsw);
        try{
            userRepo.getInstance().addUser(newUser);
            response.sendRedirect("./admin.html");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
